package com.xnyzc.lhy.mis.service.impl.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xnyzc.lhy.common.component.config.GlobalConfig;
import com.xnyzc.lhy.common.constant.MessageConstant;
import com.xnyzc.lhy.common.entity.ParameterEnum;
import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.exception.PangException;
import com.xnyzc.lhy.common.global.Configuration;
import com.xnyzc.lhy.common.penum.EErrorCode;
import com.xnyzc.lhy.common.penum.EOrderType;
import com.xnyzc.lhy.common.penum.order.EOrderStatus;
import com.xnyzc.lhy.common.penum.star.EStarType;
import com.xnyzc.lhy.common.util.CheckUtil;
import com.xnyzc.lhy.common.util.EmptyUtil;
import com.xnyzc.lhy.common.util.StringUtil;
import com.xnyzc.lhy.mis.entity.dictionaries.OaSysDict;
import com.xnyzc.lhy.mis.entity.order.*;
import com.xnyzc.lhy.mis.entity.param.order.DOrderDetailsResults;
import com.xnyzc.lhy.mis.entity.param.order.PassengersOrderResults;
import com.xnyzc.lhy.mis.mapper.dictionaries.OaSysDictMapper;
import com.xnyzc.lhy.mis.mapper.order.*;
import com.xnyzc.lhy.mis.service.comment.IOaSysCommentService;
import com.xnyzc.lhy.mis.service.order.IOaDOrderCorrelationService;
import io.swagger.models.auth.In;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * <p>
 * 司机接单表 服务实现类
 * </p>
 *
 * @author huxuekuo
 * @since 2019-07-19
 */
@Service
public class OaDOrderCorrelationServiceImpl extends ServiceImpl<OaDOrderMapper, OaDOrder> implements IOaDOrderCorrelationService {

    /**
     * 司机订单Mapper
     */
    @Autowired
    private OaDOrderMapper oaDOrderMapper;

    /**
     * 订单评价表Mapper
     */
    @Autowired
    private OaOrderEvaluationMapper oaOrderEvaluationMapper;

    /**
     * 叫车审批Mapper
     */
    @Autowired
    private OaCOrderApprovalOfficialMapper oaCOrderApprovalOfficialMapper;

    /**
     * 部门公务Mapper
     */
    @Autowired
    private  OaCOrderDeptOfficialMapper oaCOrderDeptOfficialMapper;

    /**
     * 自费叫车Mapper
     */
    @Autowired
    private  OaCOrderPersonalMapper oaCOrderPersonalMapper;

    /**
     * 个人公务Mapper
     */
    @Autowired
    private  OaCOrderPersonalOfficialMapper oaCOrderPersonalOfficialMapper;

    /**
     * 订单状态字典Mapper
     */
    @Autowired
    private OaSysDictMapper oaSysDictMapper;

    /**
     * 引用方法
     */
    @Autowired
    private IOaSysCommentService iOaSysCommentService;

    /**
     * 订单列表
     * @param userId   司机用户ID
     * @param type   订单类型
     * @param page   页码
     * @return
     */
    @Override
    public Rv dOrderList(Long userId,String type,Integer page) {
        //必填验证
        //type 全部:all 未支付:arrearage 已取消:cancel
        if(StringUtils.isBlank(type)||CheckUtil.objIsEmpty(page)){
            throw PangException.create(EErrorCode.noData);
        }
        //查询用车类型字典
        List<OaSysDict> orderLevelDictList=getOrderLevelDict();
        if(EmptyUtil.isEmpty(orderLevelDictList)){
            throw PangException.create(EErrorCode.noData);
        }
        // 查询审批订单
        List<OaCOrderApprovalOfficial> approvalOfficialList=getOrderApprovalOfficialByDriverId(userId,type);
        // 查询个人公务订单
        List<OaCOrderPersonalOfficial> personalOfficialList=getOrderPersonalOfficialByDriverId(userId,type);
        // 查询自费叫车订单
        List<OaCOrderPersonal> personalList=getOrderPersonalByDriverId(userId,type);
        // 查询部门公务订单
        List<OaCOrderDeptOfficial> deptOfficialList=getOrderDeptByDriverId(userId,type);
        List<PassengersOrderResults> collectList=new ArrayList<>();
        collectList=getDataMerge(collectList,approvalOfficialList,personalOfficialList,personalList,deptOfficialList);
        List<PassengersOrderResults> resultsList=new ArrayList<>();
        if(EmptyUtil.isEmpty(collectList)){
            return Rv.wrap(EErrorCode.success, resultsList);
        }else{
            // 遍历车型
            for(PassengersOrderResults collect:collectList){
                for(OaSysDict level:orderLevelDictList){
                    if(collect.getVehicleType().equals(Integer.valueOf(level.getValue()))){
                        collect.setVehicleTypeStr(level.getLabel());
                    }
                }
            }
        }
        //数据处理
        resultsList=getOrderDataProcessing(collectList,page);
        return Rv.wrap(EErrorCode.success, resultsList);
    }



    public List<PassengersOrderResults> getDataMerge(List<PassengersOrderResults> collectList,List<OaCOrderApprovalOfficial> approvalOfficialList,List<OaCOrderPersonalOfficial> personalOfficialList,
                                                     List<OaCOrderPersonal> personalList,List<OaCOrderDeptOfficial> deptOfficialList){
        PassengersOrderResults result=new PassengersOrderResults();
        // 审批订单
        if(!EmptyUtil.isEmpty(approvalOfficialList)){
            for(OaCOrderApprovalOfficial official : approvalOfficialList){
                result=new PassengersOrderResults();
                result.setVehicleType(official.getVehicleType());
                result.setId(official.getApprovalOfficialId());
                result.setIsCarpool(0);
                result.setPassengerPhone("");
                if(StringUtils.isNotEmpty(official.getPassengerPhone())){
                    String phone=official.getPassengerPhone().substring(official.getPassengerPhone().length()-4,official.getPassengerPhone().length());
                    result.setPassengerPhone(phone);
                }
                result.setTitle(MessageConstant.AUDITOFFICIAL);
                result.setOrderNo(official.getOrderNo());
                result.setEndAddress(official.getEndAddress());
                result.setOrderStatus(official.getOrderStatus());
                result.setOrderTime(getDateConversion(official.getOrderTime()));
                result.setOrderType(official.getOrderType());
                result.setStartAddress(official.getStartAddress());
                collectList.add(result);
            }
        }
        // 部门公务订单
        if(!EmptyUtil.isEmpty(deptOfficialList)){
            for(OaCOrderDeptOfficial official : deptOfficialList){
                result=new PassengersOrderResults();
                result.setIsCarpool(0);
                result.setVehicleType(official.getVehicleType());
                result.setPassengerPhone("");
                if(StringUtils.isNotEmpty(official.getPassengerPhone())){
                    String phone=official.getPassengerPhone().substring(official.getPassengerPhone().length()-4,official.getPassengerPhone().length());
                    result.setPassengerPhone(phone);
                }
                result.setTitle(MessageConstant.DEPTOFFICIAL);
                result.setOrderNo(official.getOrderNo());
                result.setEndAddress(official.getEndAddress());
                result.setOrderStatus(official.getOrderStatus());
                result.setOrderTime(getDateConversion(official.getOrderTime()));
                result.setOrderType(official.getOrderType());
                result.setStartAddress(official.getStartAddress());
                collectList.add(result);
            }
        }
        //查询自费叫车订单
        if(!EmptyUtil.isEmpty(personalList)){
            for(OaCOrderPersonal personal : personalList){
                result=new PassengersOrderResults();
                result.setVehicleType(personal.getVehicleType());
                result.setTitle(MessageConstant.PERSONALCALL);
                result.setOrderNo(personal.getOrderNo());
                result.setEndAddress(personal.getEndAddress());
                result.setOrderStatus(personal.getOrderStatus());
                result.setOrderTime(getDateConversion(personal.getOrderTime()));
                result.setOrderType(personal.getOrderType());
                result.setStartAddress(personal.getStartAddress());
                result.setIsCarpool(personal.getIsCarpool());
                result.setPassengerPhone("");
                if(StringUtils.isNotEmpty(personal.getPassengerPhone())){
                    String phone=personal.getPassengerPhone().substring(personal.getPassengerPhone().length()-4,personal.getPassengerPhone().length());
                    result.setPassengerPhone(phone);
                }
                collectList.add(result);
            }
        }
        //查询个人公务订单
        if(!EmptyUtil.isEmpty(personalOfficialList)){
            for(OaCOrderPersonalOfficial official : personalOfficialList){
                result=new PassengersOrderResults();
                result.setIsCarpool(0);
                result.setVehicleType(official.getVehicleType());
                result.setPassengerPhone("");
                if(StringUtils.isNotEmpty(official.getPassengerPhone())){
                    String phone=official.getPassengerPhone().substring(official.getPassengerPhone().length()-4,official.getPassengerPhone().length());
                    result.setPassengerPhone(phone);
                }
                result.setTitle(MessageConstant.PERSONALOFFICIAL);
                result.setOrderNo(official.getOrderNo());
                result.setEndAddress(official.getEndAddress());
                result.setOrderStatus(official.getOrderStatus());
                result.setOrderTime(getDateConversion(official.getOrderTime()));
                result.setOrderType(official.getOrderType());
                result.setStartAddress(official.getStartAddress());
                collectList.add(result);
            }
        }
        return collectList;
    }

    /**
     * 通过userId查询审批公务订单
     * @param userId
     * @return
     */
    private List<OaCOrderApprovalOfficial> getOrderApprovalOfficialByDriverId(Long userId,String type){
        QueryWrapper<OaCOrderApprovalOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderApprovalOfficial.DRIVER_ID,userId);
        if(type.equals(GlobalConfig.ARREARAGE)){
            // 未支付
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.normalOrderPendingPayment.getType());
            status.add(EOrderStatus.cancelOrdersFeesPaid.getType());
            queryWrapper.in(OaCOrderApprovalOfficial.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.CANCEL)){
            // 已取消
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.in(OaCOrderApprovalOfficial.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.ALL)){
            // 全部
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.notIn(OaCOrderApprovalOfficial.ORDER_STATUS,status);
        }
        List<OaCOrderApprovalOfficial> approvalOfficialList = oaCOrderApprovalOfficialMapper.selectList(queryWrapper);
        return approvalOfficialList;
    }

    /**
     * 通过userId查询部门公务订单
     * @param userId
     * @return
     */
    private List<OaCOrderDeptOfficial> getOrderDeptByDriverId(Long userId,String type){
        QueryWrapper<OaCOrderDeptOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderDeptOfficial.DRIVER_ID,userId);
        if(type.equals(GlobalConfig.ARREARAGE)){
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.normalOrderPendingPayment.getType());
            status.add(EOrderStatus.cancelOrdersFeesPaid.getType());
            // 未支付
            queryWrapper.in(OaCOrderDeptOfficial.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.CANCEL)){
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.in(OaCOrderDeptOfficial.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.ALL)){
            // 全部
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.notIn(OaCOrderDeptOfficial.ORDER_STATUS,status);
        }
        List<OaCOrderDeptOfficial> deptOfficialList = oaCOrderDeptOfficialMapper.selectList(queryWrapper);
        return deptOfficialList;
    }

    /**
     * 通过userId查询自费叫车订单
     * @param userId
     * @return
     */
    private List<OaCOrderPersonal> getOrderPersonalByDriverId(Long userId,String type){
        QueryWrapper<OaCOrderPersonal> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderPersonal.DRIVER_ID,userId);
        if(type.equals(GlobalConfig.ARREARAGE)){
            // 未支付
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.normalOrderPendingPayment.getType());
            status.add(EOrderStatus.cancelOrdersFeesPaid.getType());
            queryWrapper.in(OaCOrderPersonal.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.CANCEL)){
            // 已取消
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.in(OaCOrderPersonal.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.ALL)){
            // 全部
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.notIn(OaCOrderPersonal.ORDER_STATUS,status);
        }
        List<OaCOrderPersonal> personalList = oaCOrderPersonalMapper.selectList(queryWrapper);
        return personalList;
    }

    /**
     * 通过userId查询个人公务订单
     * @param userId
     * @return
     */
    private List<OaCOrderPersonalOfficial> getOrderPersonalOfficialByDriverId(Long userId,String type){
        QueryWrapper<OaCOrderPersonalOfficial> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaCOrderPersonalOfficial.DRIVER_ID,userId);
        if(type.equals(GlobalConfig.ARREARAGE)){
            // 未支付
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.normalOrderPendingPayment.getType());
            status.add(EOrderStatus.cancelOrdersFeesPaid.getType());
            queryWrapper.in(OaCOrderPersonalOfficial.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.CANCEL)){
            // 已取消
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.ne(OaCOrderPersonalOfficial.ORDER_STATUS,status);
        }else if(type.equals(GlobalConfig.ALL)){
            // 全部
            List<Integer> status=new ArrayList<>();
            status.add(EOrderStatus.cancelOrderNoNeedPayment.getType());
            status.add(EOrderStatus.abnormalEndOrder.getType());
            queryWrapper.notIn(OaCOrderPersonalOfficial.ORDER_STATUS,status);
        }
        List<OaCOrderPersonalOfficial> personalOfficialList = oaCOrderPersonalOfficialMapper.selectList(queryWrapper);
        return personalOfficialList;
    }

    /**
     * Date转String
     * @param date
     * @return
     */
    public String getDateConversion(Date date){
        String time="";
        if(CheckUtil.objIsEmpty(date)) {
            return time;
        }
        Instant instant = date.toInstant();
        ZoneId zone = ZoneId.systemDefault();
        LocalDateTime localTime = LocalDateTime.ofInstant(instant, zone);
        DateTimeFormatter formater = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        time=formater.format(localTime);
        return time;
    }

    /**
     * 查询订单状态字典表
     * @return
     */
    private List<OaSysDict> getOrderDict(){
        QueryWrapper<OaSysDict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaSysDict.TYPE,"order_status");
        List<OaSysDict> orderDictList = oaSysDictMapper.selectList(queryWrapper);
        return orderDictList;
    }

    /**
     * 查询车型字典表
     * @return
     */
    private List<OaSysDict> getOrderLevelDict(){
        QueryWrapper<OaSysDict> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaSysDict.TYPE,"require_level");
        List<OaSysDict> orderDictList = oaSysDictMapper.selectList(queryWrapper);
        return orderDictList;
    }

    /**
     * 订单列表数据处理
     * @return
     */
    public List<PassengersOrderResults> getOrderDataProcessing(List<PassengersOrderResults> collectList,Integer page){
        for (PassengersOrderResults results : collectList) {
            // 0、3、4、5、6、13、14行程中 7、9待支付 10、11已取消 12已支付 15审核通过
            if (results.getOrderStatus().equals(EOrderStatus.waitingResponse.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.driverOrder.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.reservationLocation.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.driverArrived.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.duringTrip.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.privateItinerary.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.sendBill.getType())) {
                results.setOrderStatusStr(MessageConstant.THETRIP);
            } else if (results.getOrderStatus().equals(EOrderStatus.normalOrderPendingPayment.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.cancelOrdersFeesPaid.getType())) {
                results.setOrderStatusStr(MessageConstant.UNPAID);
            } else if (results.getOrderStatus().equals(EOrderStatus.cancelOrderNoNeedPayment.getType()) ||
                    results.getOrderStatus().equals(EOrderStatus.abnormalEndOrder.getType())) {
                results.setOrderStatusStr(MessageConstant.CANCELED);
            } else if (results.getOrderStatus().equals(EOrderStatus.paymented.getType())) {
                results.setOrderStatusStr(MessageConstant.HAVEPAY);
            } else if (results.getOrderStatus().equals(EOrderStatus.examination.getType())) {
                results.setOrderStatusStr(MessageConstant.APPROVED);
            }
        }
        List<PassengersOrderResults> list= getSort(collectList,page);
        return list;
    }

    /**
     * 排序
     * @param collectList
     * @param page
     * @return
     */
    public List<PassengersOrderResults>  getSort(List<PassengersOrderResults> collectList,Integer page){
        Collections.sort(collectList, new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                PassengersOrderResults w1 = (PassengersOrderResults) o1;
                PassengersOrderResults w2 = (PassengersOrderResults) o2;
                return w2.getOrderTime().compareTo(w1.getOrderTime());
            }
        });
        Integer pageSize= Configuration.pageSize;
        if(collectList.size()>=pageSize*(page)){
            collectList=collectList.subList(pageSize*(page-1), pageSize*(page));
        }else{
            if(collectList.size()>=pageSize*(page-1)){
                collectList=collectList.subList(pageSize*(page-1), collectList.size());
            }else{
                List<PassengersOrderResults> list=new ArrayList<>();
                return list;
            }
        }
        return collectList;
    }

    /**
     * 司机端订单详情
     * @param orderNo
     * @return
     */
    @Override
    public Rv dOrderDetails(String orderNo, String userType, String tag){
        //必填验证
        if(StringUtils.isBlank(orderNo)){
            throw PangException.create(EErrorCode.noData);
        }
        //返回参数
        List<DOrderDetailsResults> resultsList=new ArrayList<>();
        DOrderDetailsResults results=new DOrderDetailsResults();
        //查询订单状态字典
        List<OaSysDict> orderDictList=getOrderDict();
        if(EmptyUtil.isEmpty(orderDictList)){
            throw PangException.create(EErrorCode.noData);
        }
        Long userOrderNo=0L;
        //审批公务订单
        if (orderNo.contains(EOrderType.SPGW.getValue())) {
            OaCOrderApprovalOfficial official=getOrderApprovalOfficialByOrder(orderNo);
            userOrderNo=official.getApprovalOfficialId();
            results.setStartAddress(official.getStartAddress());
            results.setEndAddress(official.getEndAddress());
            OaOrderEvaluation orderEvaluation=getOrderEvaluation(userOrderNo);
            if(CheckUtil.objIsEmpty(orderEvaluation)){
                results.setStar("");
            }else{
                results.setStar(orderEvaluation.getEvaluationScore());
            }
            results.setOrderStatus(official.getOrderStatus());
            String orderStatusStr=getOrderStatus(official.getOrderStatus(),orderDictList);
            results.setOrderStatusStr(orderStatusStr);
        } else if (orderNo.contains(EOrderType.BMGW.getValue())) {
            //部门公务订单
            OaCOrderDeptOfficial official=getOrderDeptByOrderNo(orderNo);
            userOrderNo=official.getDeptOfficialId();
            results.setStartAddress(official.getStartAddress());
            results.setEndAddress(official.getEndAddress());
            OaOrderEvaluation orderEvaluation=getOrderEvaluation(userOrderNo);
            if(CheckUtil.objIsEmpty(orderEvaluation)){
                results.setStar("");
            }else{
                results.setStar(orderEvaluation.getEvaluationScore());
            }
            results.setOrderStatus(official.getOrderStatus());
            String orderStatusStr=getOrderStatus(official.getOrderStatus(),orderDictList);
            results.setOrderStatusStr(orderStatusStr);
        }else if (orderNo.contains(EOrderType.ZFJC.getValue())) {
            //自费
            OaCOrderPersonal official=getOrderPersonalByOrderNo(orderNo);
            userOrderNo=official.getPersonalId();
            results.setStartAddress(official.getStartAddress());
            results.setEndAddress(official.getEndAddress());
            OaOrderEvaluation orderEvaluation=getOrderEvaluation(userOrderNo);
            if(CheckUtil.objIsEmpty(orderEvaluation)){
                results.setStar("");
            }else{
                results.setStar(orderEvaluation.getEvaluationScore());
            }
            results.setOrderStatus(official.getOrderStatus());
            String orderStatusStr=getOrderStatus(official.getOrderStatus(),orderDictList);
            results.setOrderStatusStr(orderStatusStr);
        } else if (orderNo.contains(EOrderType.GRGW.getValue())) {
            OaCOrderPersonalOfficial official=getOrderPersonalOfficialByOrderNo(orderNo);
            userOrderNo=official.getPersonalOfficialId();
            results.setStartAddress(official.getStartAddress());
            results.setEndAddress(official.getEndAddress());
            OaOrderEvaluation orderEvaluation=getOrderEvaluation(userOrderNo);
            if(CheckUtil.objIsEmpty(orderEvaluation)){
                results.setStar("");
            }else{
                results.setStar(orderEvaluation.getEvaluationScore());
            }
            results.setOrderStatus(official.getOrderStatus());
            String orderStatusStr=getOrderStatus(official.getOrderStatus(),orderDictList);
            results.setOrderStatusStr(orderStatusStr);
        }
        // 数据整理
        getDOrderResults(results,userOrderNo,userType,tag);
        return Rv.wrap(EErrorCode.success, results);
    }

    /**
     * 司机订单整合
     * @param results
     * @param orderNo
     */
    public void getDOrderResults (DOrderDetailsResults results,Long orderNo,String userType, String tag){
        OaDOrder oaDOrder=getDOrderList(orderNo);
        if(CheckUtil.objIsEmpty(oaDOrder)){
            throw PangException.create(EErrorCode.noData);
        }
        results.setTotalFee("");
        if(CheckUtil.objIsNotEmpty(oaDOrder.getTotalCost())){
            results.setTotalFee(String.valueOf(oaDOrder.getTotalCost()));
        }
        results.setIsCarpool(oaDOrder.getIsCarpool());
        results.setIsComment(oaDOrder.getIsComment());
        results.setIsLayout(0);
        results.setStarShowName("");
        String phone="";
        if(StringUtils.isNotEmpty(oaDOrder.getPassengerPhone())){
            if(oaDOrder.getPassengerPhone().length()>4){
                phone=oaDOrder.getPassengerPhone().substring(oaDOrder.getPassengerPhone().length()-4,oaDOrder.getPassengerPhone().length());
            }
        }
        results.setPassengerPhone(phone);
        //评价集合
        List mdictResult=new ArrayList();
        ParameterEnum type = ParameterEnum.fromTypeName(String.valueOf(results.getIsComment()));
        switch(type) {
            case ZERO:
                mdictResult=iOaSysCommentService.getComment(userType, tag);
                results.setIsLayout(1);
                break;
            default:
                if(StringUtils.isNotEmpty(results.getStar())){
                    results.setStarShowName(EStarType.findById(Integer.valueOf(results.getStar())).getValue());
                }
                if(results.getOrderStatus().equals(ParameterEnum.SEVEN.getType())||results.getOrderStatus().equals(ParameterEnum.TWELVE.getType())){
                    results.setIsLayout(1);
                }
                break;
        }
        results.setDictMap(mdictResult);
    }

    /**
     * 获取订单状态
     * @return
     */
    private String getOrderStatus(Integer orderStatus,List<OaSysDict> orderDictList){
        String status="";
        for(OaSysDict dict:orderDictList){
            if(orderStatus.equals(Integer.valueOf(dict.getValue()))){
                status=dict.getLabel();
                break;
            }
        }
        return status;
    }

    /**
     * 查询司机接单表
     * @return
     */
    private OaDOrder getDOrderList(Long orderNo){
        QueryWrapper<OaDOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaDOrder.USER_ORDER_NO,String.valueOf(orderNo));
        OaDOrder oaDOrder = oaDOrderMapper.selectOne(queryWrapper);
        return oaDOrder;
    }

    /**
     * 查询订单评价表
     * @return
     */
    private OaOrderEvaluation getOrderEvaluation(Long orderNoId){
        QueryWrapper<OaOrderEvaluation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(OaOrderEvaluation.USER_TYPE,0);
        queryWrapper.eq(OaOrderEvaluation.ORDER_NO,orderNoId);
        OaOrderEvaluation oaOrderEvaluation = oaOrderEvaluationMapper.selectOne(queryWrapper);
        return oaOrderEvaluation;
    }


    /**
     * 通过orderNo查询审批公务订单
     * @param orderNo 订单号
     * @return
     */
    public OaCOrderApprovalOfficial getOrderApprovalOfficialByOrder(String orderNo) {
        QueryWrapper<OaCOrderApprovalOfficial> wrapper = new QueryWrapper<>();
        wrapper.eq(OaCOrderApprovalOfficial.ORDER_NO, orderNo);
        return oaCOrderApprovalOfficialMapper.selectOne(wrapper);
    }


    /**
     * 通过orderNo查询部门公务订单
     * @param orderNo
     * @return
     */
    private OaCOrderDeptOfficial getOrderDeptByOrderNo(String orderNo){
        QueryWrapper<OaCOrderDeptOfficial> wrapper = new QueryWrapper<>();
        wrapper.eq(OaCOrderDeptOfficial.ORDER_NO, orderNo);
        return oaCOrderDeptOfficialMapper.selectOne(wrapper);
    }

    /**
     * 通过orderNo查询自费叫车订单
     * @param orderNo
     * @return
     */
    private OaCOrderPersonal getOrderPersonalByOrderNo(String orderNo){
        QueryWrapper<OaCOrderPersonal> wrapper = new QueryWrapper<>();
        wrapper.eq(OaCOrderPersonal.ORDER_NO, orderNo);
        return oaCOrderPersonalMapper.selectOne(wrapper);
    }

    /**
     * 通过orderNo查询个人公务订单
     * @param orderNo
     * @return
     */
    private OaCOrderPersonalOfficial getOrderPersonalOfficialByOrderNo(String orderNo){
        QueryWrapper<OaCOrderPersonalOfficial> wrapper = new QueryWrapper<>();
        wrapper.eq(OaCOrderPersonalOfficial.ORDER_NO, orderNo);
        return oaCOrderPersonalOfficialMapper.selectOne(wrapper);
    }

}
